home *** CD-ROM | disk | FTP | other *** search
- /* based on funzip.c from unzip 5.40 */
-
- #define IGNORE_STDIO_STUBS
- #define __string_h
-
- #ifdef OLDGCC
-
- #include <Common.h>
- #include <System/SysAll.h>
- #include <UI/UIAll.h>
- #include <Unix/sys_types.h>
-
- #else
-
- #include <PalmOS.h>
- #include <PalmCompatibility.h>
- #include <Unix/sys_types.h>
-
- #endif
-
- #include "stringil.h"
- #include "stdio2.h"
-
- #ifdef __PALMOS_TRAPS__
- Err errno;
- #endif
-
- extern int fgetc(FILE * fp);
- extern FILE *fopen(char *name, char *mode);
-
- int untardir(FILE * fd, char *dir, long int *loc)
- {
- char ibuf[512], *c;
- unsigned long total;
- int max;
-
- max = 0;
- *dir = 0;
- dir[1]= 0;
-
- fseek(fd, 0, SEEK_SET);
-
- fread(ibuf, 1, 512, fd);
- if (strncmp(&ibuf[257], "GNUtar",6) && strncmp(&ibuf[257], "ustar", 5))
- return 0;
-
- fseek(fd, 0, SEEK_SET);
-
- for (;;) {
- fread(ibuf, 1, 512, fd);
-
- if (ibuf[0] == 0)
- fread(ibuf, 1, 512, fd);
-
- if (strncmp(&ibuf[257], "GNUtar",6) && strncmp(&ibuf[257], "ustar", 5))
- return max;
-
- *loc++ = ftell(fd) - 512L;
-
- strcpy(dir,ibuf);
- dir += strlen(dir);
- *++dir = 0;
-
- c = &ibuf[124];
- while (*c == ' ')
- c++;
- total = 0;
-
- do {
- total = (total << 3) + *c++ - '0';
- } while (*c != ' ');
-
- // round to the block size
- total += 512;
- total &= ~511;
- fseek(fd, total, SEEK_CUR);
- max++;
-
- }
-
-
- }
-
- int untar(FILE * fd, long int loc)
- {
- char ibuf[512], *c;
- unsigned long total, itot;
- FILE *ofd;
- RectangleType r;
-
- fseek(fd, 0, SEEK_SET);
-
- fread(ibuf, 1, 512, fd);
- if (strncmp(&ibuf[257], "GNUtar",6) && strncmp(&ibuf[257], "ustar", 5))
- return -1;
-
- if( loc == -1 ) {
- fseek(fd, 0, SEEK_SET);
- FileControl(fileOpDestructiveReadMode, fd, NULL, NULL);
- }
- else
- fseek(fd, loc, SEEK_SET);
-
- for (;;) {
-
- fread(ibuf, 1, 512, fd);
-
- if (ibuf[0] == 0)
- fread(ibuf, 1, 512, fd);
-
- if (strncmp(&ibuf[257], "GNUtar",6) && strncmp(&ibuf[257], "ustar", 5))
- return 0;
-
- r.topLeft.x = 0, r.topLeft.y = 15, r.extent.x = 160, r.extent.y = 30;
- WinEraseRectangle(&r, 0);
-
- r.topLeft.x = 0, r.topLeft.y = 30, r.extent.x = 160, r.extent.y = 15;
-
-
- c = &ibuf[124];
- while (*c == ' ')
- c++;
- total = 0;
-
- do {
- total = (total << 3) + *c++ - '0';
- } while (*c != ' ');
-
- ofd = fopen(ibuf, "w");
-
-
- StrIToA(ibuf,total);
- strcat(ibuf," ");
- WinDrawChars(ibuf,strlen(ibuf),120,0);
-
-
- itot = total;
- while (total) {
-
- fread(ibuf, 1, 512, fd);
- fwrite(ibuf, 1, total > 512 ? 512 : total, ofd);
- total -= total > 512 ? 512 : total;
- r.extent.x = 160 - (160 * total / itot);
- WinDrawRectangle(&r, 0);
- }
- fclose(ofd);
-
- if( loc != -1 )
- break;
-
- }
- return 0;
-
- }
-